package com.example.online_exam_system.service.impl;

import com.example.online_exam_system.entity.StuExam;
import com.example.online_exam_system.dao.StuExamDao;
import com.example.online_exam_system.service.StuExamService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * (StuExam)表服务实现类
 *
 * @author lianglong
 * @since 2022-03-20 10:54:40
 */
@Service("stuExamService")
public class StuExamServiceImpl implements StuExamService {
    @Resource
    private StuExamDao stuExamDao;

    @Override
    public List<StuExam> queryExamCheck() {
        return stuExamDao.queryExamCheck();
    }

    /**
     * 通过ID查询单条数据
     *
     * @param  主键
     * @return 实例对象
     */
    @Override
    public StuExam queryById( ) {
        return this.stuExamDao.queryById();
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<StuExam> queryAllByLimit(int offset, int limit) {
        return this.stuExamDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param stuExam 实例对象
     * @return 实例对象
     */
    @Override
    public StuExam insert(StuExam stuExam) {
        this.stuExamDao.insert(stuExam);
        return stuExam;
    }



    /**
     * 通过主键删除数据
     *
     * @param  主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById( ) {
        return this.stuExamDao.deleteById() > 0;
    }

    @Override
    public void batchinsert(ArrayList<StuExam> list) {
        list.forEach(stuExam -> {
            insert(stuExam);
        });
    }

    @Override
    public int updateExamCheck(List<StuExam> list) {
        list.forEach(stuExam -> {
            int update = stuExamDao.update(stuExam);
        });
        return list.size();
    }

    @Override
    public List<StuExam> queryExamByuserId(String userId) {
        return stuExamDao.queryExamByuserId(userId);
    }

    @Override
    public int updateScore(Map<String, Object> map) {
        return stuExamDao.updateScore(map);
    }

    @Override
    public List<Map<String, Object>> queryScore1(String username) {
        return stuExamDao.queryScore1(username);
    }

    @Override
    public Map<String, Object> getTotalScore(String testname) {
        return stuExamDao.getTotalScore(testname);
    }

    @Override
    public Map<String, Object> getExamInfo(String userId, String testId) {
        return stuExamDao.getExamInfo(userId,testId);
    }

    @Override
    public List<Map<String, Object>> getExamInfo2(String userId, String testId) {
        return stuExamDao.getExamInfo2(userId,testId);
    }

}
